export default [
  //路由重定向，设置默认路由
  {
    path: "/",
    redirect: "home",
  },
  {
    path: "/home",
    name: "home",
    //懒加载的推荐写法
    component: () => import("@/pages/Home"),
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/pages/Login"),
    meta: {
      isFooterShow: true,
    },
  },
  {
    path: "/register",
    name: "register",
    component: () => import("@/pages/Register"),
    meta: {
      isFooterShow: true,
    },
  },
  {
    path: "/search:keyword?",
    name: "search",
    component: () => import("@/pages/Search"),
  },
  {
    path: "/detail/:skuId",
    name: "detail",
    component: () => import("@/pages/Detail"),
  },
  {
    path: "/addcartsuccess",
    name: "addcartsuccess",
    component: () => import("@/pages/AddCartSuccess"),
    //路由独享守卫
    beforeEnter: (to, from, next) => {
      //判断如果来的路由地址是商品详情页,则放行,否则导航到商品详情页
      if (from.name === "detail") {
        next()
      } else {
        next("/detail")
      }
    },
  },
  {
    path: "/shopcart",
    name: "shopcart",
    component: () => import("@/pages/ShopCart"),
  },
  {
    path: "/trade",
    name: "trade",
    component: () => import("@/pages/Trade"),
    //路由独享守卫
    beforeEnter: (to, from, next) => {
      //判断如果来的路由地址是购物车,则放行,否则导航到购物车
      if (from.name === "shopcart") {
        next()
      } else {
        next("/shopcart")
      }
    },
  },
  {
    path: "/center",
    // name: "center",
    component: () => import("@/pages/Center"),
    redirect: "/center/myorder",
    children: [
      {
        path: "/center/myorder",
        name: "myorder",
        component: () => import("@/pages/Center/components/MyOrder"),
      },
      {
        path: "/center/teamorder",
        name: "teamorder",
        component: () => import("@/pages/Center/components/TeamOrder"),
      },
    ],
  },
  {
    path: "/pay",
    name: "pay",
    component: () => import("@/pages/Pay"),
    //路由独享守卫
    beforeEnter: (to, from, next) => {
      //判断如果来的路由地址是交易页,则放行,否则导航到购物车
      if (from.name === "trade") {
        next()
      } else {
        next("/shopcart")
      }
    },
  },
  {
    path: "/paysuccess",
    name: "paysuccess",
    component: () => import("@/pages/PaySuccess"),
    //路由独享守卫
    beforeEnter: (to, from, next) => {
      //判断如果来的路由地址是支付页,则放行,否则导航到购物车
      if (from.name === "pay") {
        next()
      } else {
        next("/shopcart")
      }
    },
  },
]
